package com.achao.backstagemanage.service.impl;

import com.achao.backstagemanage.dao.MusicManagerDao;
import com.achao.backstagemanage.service.MusicManagerService;
import com.achao.backstagemanage.vo.MusicManagerVO;
import com.achao.basecommon.entity.MusicManagerDO;
import com.achao.basecommon.utils.CommonUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述：后台管理者相关类-业务层实现类
 *
 * @Author：yangchao
 * @CreateDate：2023/2/1 21:30
 */
@Service
public class MusicManagerServiceImpl implements MusicManagerService {

    @Autowired
    private MusicManagerDao musicManagerDao;
    //这个是测试案例
    @Override
    public List<MusicManagerDO> queryManagerList() {
        QueryWrapper<MusicManagerDO> wrapper = new QueryWrapper<>();
        wrapper.eq("ID",1);
        return musicManagerDao.selectList(wrapper);
    }

    /**
     *  描述：查询管理用户
     *      @Param：musicManagerDO
     *      @Returen：MusicManagerDO
     */
    @Override
    public MusicManagerDO queryRegisterManager(MusicManagerDO musicManagerDO) {
        QueryWrapper<MusicManagerDO> wrapper = new QueryWrapper<>();
        wrapper.eq("MANAGER_NAME",musicManagerDO.getManagerName().trim());
        return musicManagerDao.selectOne(wrapper);
    }

    /**
     *  描述：添加管理账户
     *      @Param：musicManagerVO
     *      @Returen：void
     */
    @Override
    public void insertRegistryMangage(MusicManagerDO musicManagerDO) {
        musicManagerDao.insert(musicManagerDO);
    }

    /**
     *  描述：分页查询所有管理人员信息
     *      @Param：null
     *      @Returen：List<MusicManagerDO>
     */
    @Override
    public List<MusicManagerDO> queryAllManagerList() {
        return musicManagerDao.queryAllManagerList();
    }

    /**
     *  描述：根据ID查询管理员信息
     *      @Param：id
     *      @Returen：MusicManagerDO
     */
    @Override
    public MusicManagerDO queryManagerForId(Integer id){
        if(0 == id){
            CommonUtils.throwMusicConmonException("查询id不允许为空或0");
        }
        return musicManagerDao.queryManagerForId(id);
    }

    /**
     *  描述：根据ID-编辑管理员信息
     *      @Param：musicManagerDO
     *      @Returen：Integer
     */
    @Override
    public Integer updateManagerInfo(MusicManagerDO musicManagerDO) {
        if(0 == musicManagerDO.getId()){
            CommonUtils.throwMusicConmonException("需要ID，更新管理员信息");
        }
        return musicManagerDao.updateById(musicManagerDO);
    }

    /**
     *  描述：根据ID-删除管理员信息
     *      @Param：id
     *      @Returen：void
     */
    @Override
    public void delManagerInfo(Integer id) {
        if(0 == id){
            CommonUtils.throwMusicConmonException("需要ID，更新管理员信息");
        }
        musicManagerDao.deleteById(id);
    }

    /**
     *  @Description：添加管理员信息
     *  @Param：MusicManagerDO
     *  @Returen：void
     */
    @Override
    public void saveManagerInfo(MusicManagerDO musicManagerDO) {
        musicManagerDao.insert(musicManagerDO);
    }
}
